home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / apport-unpack < prev    next >
Encoding:
Text File  |  2007-04-27  |  1.1 KB  |  41 lines

  1. #!/usr/bin/python
  2.  
  3. # Extract the fields of a problem report into separate files into a new or
  4. # empty directory.
  5. #
  6. # Copyright (c) 2006 Canonical Ltd.
  7. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify it
  10. # under the terms of the GNU General Public License as published by the
  11. # Free Software Foundation; either version 2 of the License, or (at your
  12. # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
  13. # the full text of the license.
  14.  
  15. import sys, os, os.path
  16.  
  17. import problem_report
  18.  
  19. if len(sys.argv) != 3:
  20.     print 'Usage: %s <report> <target directory>' % sys.argv[0]
  21.     sys.exit(1)
  22.  
  23. report = sys.argv[1]
  24. dir = sys.argv[2]
  25.  
  26. # ensure that the directory does not yet exist or is empty
  27. try:
  28.     os.mkdir(dir)
  29. except OSError:
  30.     if os.listdir(dir):
  31.         print >> sys.stderr, 'Destination directory %s exists and is not empty.'
  32.         sys.exit(1)
  33.  
  34. pr = problem_report.ProblemReport()
  35. if report == '-':
  36.     pr.load(sys.stdin)
  37. else:
  38.     pr.load(open(report))
  39. for k in pr:
  40.     open(os.path.join(dir, k), 'w').write(pr[k])
  41.